package com.free.mini.common.base;

import lombok.Getter;

/**
 * 响应码
 */
@Getter
public enum ResultCode {

    /**
     * 初始化返回码
     */
    SUCCESS(0, "success"),
    SYSTEM_ERROR(50000,"system error"),
    NO_LOGIN(50001, "you are not logged in to the system"),
    USERNAME_PASSWD_ERR(50002, "error incorrect username or password"),
    NO_AUTHORITY(50003, "no authority"),
    EXISTING_ACCOUNT_LOGON(50004, "existing account logon"),
    NO_USER(50005, "no user"),
    TOKEN_ERROR(50006, "token error"),
    IP_BLACKLIST(70000,"Matching ip blacklist"),
    RESUBMIT(70001,"resubmit"),
    REQUEST_TIMESTAMP_CHECK(70002,"request timestamp check fail"),
    PARAM_ERROR(70003,"PARAM_ERROR"),
    ;


    ResultCode(Integer key, String message) {
        this.code = key;
        this.message = message;
    }

    private final Integer code;

    private final String message;

    public static ResultCode getResultCode(int code) {
        for (ResultCode rc : ResultCode.values()) {
            if (code == rc.getCode()) {
                return rc;
            }
        }
        return ResultCode.SYSTEM_ERROR;
    }

}
